package framework;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Vector;
/**
 * 生成应用树形栏
 * @author host
 *
 */
public class JGTree {	
	com.PublicSystem sys = com.PublicSystem.getInstance();
	StringBuffer sb = new StringBuffer();
	JGMeun m = new JGMeun();
    /**
     * 创建树形栏
     * @throws Exception
     */
	public void createTree() throws Exception {
		String bmid = "";
		String bmmc = "";
		String sjbmid = "";
		String sname = "";
		String url = "";
		String bmdj = "";
		sb.append("[");
		Vector res = m.menuPid("");
		if(null != res) {
			for(int i = 0; i < res.size(); i++) {
				bmid = (String) ((Vector) res.elementAt(i)).elementAt(0);
				bmmc = (String) ((Vector) res.elementAt(i)).elementAt(1);
				bmdj = (String) ((Vector) res.elementAt(i)).elementAt(3);
				sb.append("{id: \"" + bmid + "\", text: \"" + bmmc + "\"},");
				Vector res1 = m.menuSid(bmid,"");
				if(null != res1) {				
					createNodeTree(bmid);
				}
			}
		} else {
			sb.append("{id: \"" + 1 + "\", text: \"\"},");
		}		
		sb.append("]");
		sb.replace(sb.length() - 2, sb.length() - 1, "");		
		String outputPath = com.Const.server_path + "/page/oa_bmjgb/tree.txt";		
		OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(outputPath), "UTF-8");
		BufferedWriter bw = new BufferedWriter(write);
		PrintWriter pw = new PrintWriter(bw);
		pw.println(sb);
		pw.flush();
		pw.close();
	}					
	/**
	 * 创建节点	
	 * @param sjbmid
	 * @throws Exception
	 */
	public void createNodeTree(String sjbmid) throws Exception {
		String bmid = "";
		String bmmc = "";			
		Vector res = m.menuSid(sjbmid, "");
		if(null != res) {  			 
			for(int i = 0; i < res.size(); i++) {
				bmid = (String) ((Vector) res.elementAt(i)).elementAt(0);
				bmmc = (String) ((Vector) res.elementAt(i)).elementAt(1);
				Vector ress = m.menuSid(bmid,"");
				if(null != ress) {				
					sb.append("{id: \"" + bmid + "\", text: \"" + bmmc + "\",pid: \"" + sjbmid + "\"},");
					createNodeTree(bmid);
				} else {					
					sb.append("{id: \"" + bmid + "\", text: \"" + bmmc + "\",pid: \"" + sjbmid + "\"},");
				}					
			}			
		 }
	 }					
}